
-- 霸体
local rules = {
    ['attacked'] = true,
    ['freeze'] = true,

    ['startfiredamage'] = true,
    ['firedamage'] = true,
}

local old_PushEvent = EntityScript.PushEvent 
function EntityScript:PushEvent(event,data,...)
    if rules[event] then
        if self and self:HasTag('yuemiheng') then
            return
        end
    end
    return old_PushEvent(self,event,data,...)
end

local old_HandleEvent = State.HandleEvent
function State:HandleEvent(sg,eventame,data,...)
    if rules[sg] then
        local inst = self.inst
        if inst and inst:HasTag('yuemiheng') then
            return
        end
    end
    return old_HandleEvent(self,sg,eventame,data,...)
end

-- 不会潮湿
AddPrefabPostInit("yuemiheng", function(inst)
    if not TheWorld.ismastersim then
        return inst
    end
    if inst.components.inventory then
        function inst.components.inventory:GetWaterproofness(slot,...)
            return 10000
        end
    end
end)

-- 冰冻
AddComponentPostInit('freezable',function (self)
    local old_AddColdness = self.AddColdness
    function self:AddColdness(...)
        if self.inst.prefab and self.inst.prefab == 'yuemiheng' then
            return
        end
        return old_AddColdness(self,...)
    end
end)

-- 燃烧
AddPrefabPostInit("yuemiheng", function(inst)
    if not TheWorld.ismastersim then
        return inst
    end
    inst:AddTag("fireimmune")
    if inst.components.health then
        local old_DoFireDamage = inst.components.health.DoFireDamage
        function inst.components.health:DoFireDamage(amount,...)
            if self.inst.prefab and self.inst.prefab == 'yuemiheng' then
                amount = 0
            end
            return old_DoFireDamage(self,amount,...)
        end
    end
end)

